//
//  GuieViewController.m
//  XKStudyDemo
//
//  Created by xukai on 2017/11/28.
//  Copyright © 2017年 xukai. All rights reserved.
//

#import "GuieViewController.h"

@interface GuieViewController ()
@property(nonatomic,retain)UIImageView *firstImageView;
@property(nonatomic,retain)UIButton *secondButton;
@property(nonatomic,retain)UILabel *thirdLabel;

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) NSMutableArray *vArys;

@property (nonatomic, strong) UIView *selceView;
@property (nonatomic, assign) NSInteger selectIndex;

@end

@implementation GuieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _vArys = [NSMutableArray array];

    _firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 300, 60, 60)];
    _firstImageView.image = [UIImage imageNamed:@"tabbar_home_selected"];
    [self.view addSubview:_firstImageView];
    
    _secondButton = [[UIButton alloc] initWithFrame:CGRectMake(300, 200, 100, 30)];
    [_secondButton setTitleColor:[UIColor redColor] forState:(UIControlStateNormal)];
    [_secondButton setTitle:@"我是按钮" forState:(UIControlStateNormal)];
    [self.view addSubview:_secondButton];
    
    _thirdLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 150, 200, 30)];
    _thirdLabel.font = [UIFont systemFontOfSize:15];
    _thirdLabel.textColor = [UIColor blackColor];
    _thirdLabel.text = @"我是一个Lab";
    _thirdLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_thirdLabel];
    
    [_vArys addObject:_firstImageView];
    [_vArys addObject:_secondButton];
    [_vArys addObject:_thirdLabel];
    
    
    
    _bgView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
    
//    [self adddBezierPathWith:_firstImageView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewClick)];
    [_bgView addGestureRecognizer:tap];
    
    [self bgViewClick];
}

-(void) bgViewClick
{
    if(_selectIndex == _vArys.count)
    {
        [_bgView removeFromSuperview];
    }
    else
    {
        [self adddBezierPathWith:_vArys[_selectIndex]];
        _selectIndex++;
    }
    
    
    
    
    
    
}

-(void) adddBezierPathWith:(UIView *) view
{
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRect: _bgView.bounds];
    
    UIBezierPath *clearPath = [UIBezierPath bezierPathWithArcCenter:view.center radius:50 startAngle:0 endAngle:2 * M_PI clockwise:NO];
    
    
    [path appendPath:clearPath];
    
    CAShapeLayer *shapeLayer = (CAShapeLayer *)_bgView.layer.mask;
    if(!shapeLayer) {
        shapeLayer = [CAShapeLayer layer];
        [_bgView.layer setMask: shapeLayer];
    }
    shapeLayer.path = path.CGPath;
}

@end
